﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace SmokinEditor
{
    public partial class Drag_DropControl : UserControl
    {
        public Type Type_Of_Object;
        private Editor_Tools gEditor = null;

        public Drag_DropControl()
        {
            Type_Of_Object = null;
        }
        public Drag_DropControl(Type whatType, Editor_Tools FormToEdit)
        {
            gEditor = FormToEdit;
            Type_Of_Object = whatType;
            InitializeComponent();
            this.ControlName.Text = Type_Of_Object.Name;
        }
        protected override void Select(bool directed, bool forward)
        {
            base.Select(directed, forward);
        }
        private void Drag_DropControl_MouseClick(object sender, MouseEventArgs e)
        {
            
        }

        private void Drag_DropControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (Type_Of_Object != null)
            {
                //this.DoDragDrop(Type_Of_Object, DragDropEffects.Copy);
                gEditor.SelectedObject = Type_Of_Object;
                FieldInfo constparms = Type_Of_Object.GetField("constructor_parameters", BindingFlags.NonPublic | BindingFlags.Static);
                FieldInfo constvalues = Type_Of_Object.GetField("default_const_values", BindingFlags.NonPublic | BindingFlags.Static);
                Type[] cParms = ((Type[])constparms.GetValue(null));
                Object[] dValues = ((Object[])constvalues.GetValue(null));
                gEditor.PropertyName.Text = Type_Of_Object.Name;
                gEditor.TheProperties = new Property_List(cParms, dValues, Type_Of_Object.Name);
                gEditor.PropertyChanger.SelectedObject = gEditor.TheProperties;
                gEditor.parent.FormHandle.Activate();
            }
            else
            {
                gEditor.PropertyChanger.SelectedObject = null;

            }
        }
    }
}
